$(document).ready(function () {

    // automatically focus inputs with class "focusOnPageLoad"
    $(".focusOnPageLoad").focus();

    // BEGIN Friendship doalog <=============
    $("#friendsDialog").dialog({
        autoOpen: false,
        show: "fade",
        hide: "fade",
        draggable: false,
        modal: true
    });
    $(".friendsDialogOpen").click(function() {
        $("#friendsDialog").dialog("open");
        getFriends();
        return false;
    });

    function sendSuggestion(friendshipID) {
        var suggestionUrl = $("#lnkSendSuggestion").attr("href");
        var collectionID = $("#lnkSendSuggestion").attr("rel");
        window.location.replace(suggestionUrl + collectionID + "/" + friendshipID);
    }
    function getFriends() {
        $.ajax({
            url: baseUrl + "/friends/showfriendsajax",
            context: document.body,
            success: function(data) {
                $("#friendsDialog").html(data);
                $("a.lnkFriend").click(function(e) {
                    sendSuggestion($(e.currentTarget).attr("rel"));
                    return false;
                });
            }
        });
    }
    // --------------> END friendship dialog


    // BEGIN RemindMe doalog <=============
    $("#remindMeDialog").dialog({
        autoOpen: false,
        show: "fade",
        hide: "fade",
        draggable: false,
        modal: true,
        width: 500
    });
    $(".remindMeDialogOpen").click(function() {
        $("#remindMeDialog").dialog("open");
        getPossibleMatchesFromAmazon();
        return false;
    });

    function addMovieReminder(externaMovielID) {
        var remindMeUrl = $("#lnkRemindMe").attr("href");
        var movieID = $("#lnkRemindMe").attr("rel");
        //window.location.replace(remindMeUrl + externaMovielID);
    }
    function getPossibleMatchesFromAmazon() {
        var collectionID = $("#lnkRemindMe").attr("rel");
        $.ajax({
            url: baseUrl + "/collection/findreleasedate/"+collectionID,
            context: document.body,
            success: function(data) {
                $("#remindMeDialog").html(data);
                $("a.lnkReleaseDateMovie").click(function(e) {
                    addMovieReminder($(e.currentTarget).attr("rel"));
                    return false;
                });
            }
        });
    }
    // --------------> END remindMe dialog

});

